package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.model.common.article.dto.UserSearchDto;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.enums.AppHttpCodeEnum;
import com.zhentao.pojo.ApAssociateWords;
import com.zhentao.service.ApAssociateWordsService;
import com.zhentao.mapper.ApAssociateWordsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author EWEWW
* @description 针对表【ap_associate_words】的数据库操作Service实现
* @createDate 2024-06-27 19:43:34
*/
@Service
public class ApAssociateWordsServiceImpl extends ServiceImpl<ApAssociateWordsMapper, ApAssociateWords>
    implements ApAssociateWordsService{
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public ResponseResult findAssociate(UserSearchDto userSearchDto) {
      if(userSearchDto == null){
          return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
      }
      //执行模糊查询
        Query query = new Query(Criteria.where("associateWords").regex(".*"+userSearchDto.getSearchWords()+".*"));
        List<ApAssociateWords> apAssociateWords = mongoTemplate.find(query, ApAssociateWords.class);

        return ResponseResult.okResult(apAssociateWords);
    }
}




